mui.plusReady(function() {
	//侧滑开启侧滑菜单
	window.addEventListener('swiperight', function() {
		openMenu();
	})

	//取消滚动条
	plus.webview.currentWebview().setStyle({
		scrollIndicator: 'none'
	})

	//侧滑菜单
	var main = plus.webview.currentWebview().opener();

	function openMenu() {
		plus.webview.show('index-menu', 'none', 300, function() {
			//主窗体开始侧滑并显示遮罩
			main.setStyle({
				mask: 'rgba(0,0,0,0.4)',
				left: '70%',
				transition: {
					duration: 150
				}
			});
		})
	}
	
	//轮播图
	muiObj.request('',http('carouselpic'),'',function (data) {
		var obj = $(".carousel");
		for (var i in data.message) 
		{ 
			obj[i].src = http('') + data.message[i]['path'];
		}
	})
	
	//推荐区域开始type/row
	muiObj.request('', http('viedo/图文/2'),'', function(data) {
		var html = null; 
		//服务器返回响应，根据响应结果，分析是否登录成功；
		for (var i in data.message) {
			html = '<li class="mui-table-view-cell mui-media mui-col-xs-6">\
						<a href="#" class="article" id="'+data.message[i]['aid']+'">\
							<img class="mui-media-object" src="' + http('') + data.message[i]['thumb'] + '">\
							<div class="mui-media-body">' + data.message[i]['atitle'] + '</div>\
						</a></li>';
			$("#hot").append(html);
		}
	})
	
	var begin = 0;
	//列表页开始//article/begin/row'
	muiObj.request('', http('article/0/3'),'', function(data) {
		list(data);
	});
	
	//上拉刷新
	muiObj.pullRefresh('#refreshContainer',function () 
	{
		obj = this;
		muiObj.request('get', http('article/' + (begin += 5) + '/3'),'', function(data) {
			//如果服务器有数据
			if (data.message.length > 0) {
				list(data);
				//如果还有数据显示上拉显示更多
				obj.endPullupToRefresh(false);
			} else {
				//如果没有数据了显示没有更多数据了 
				obj.endPullupToRefresh(true);
			}
		})
	})
	
	//列表开始数据循环
	function list (data) 
	{
		var html = null; 
		for (var i in data.message) {
			html = '<li class="mui-table-view-cell">\
						<a class="mui-navigate-right article" id="'+data.message[i]['aid']+'">\
							<img class="mui-media-object mui-pull-left" src="' +http('') + data.message[i]['thumb'] + '">\
							<div class="mui-media-body">' + data.message[i]['atitle'] + '<p class="mui-ellipsis">' + data.message[i]['digest'] + '</p></div>\
						</a></li>';
			$(".list").append(html);
		}
	}
	
	//文章点击
	var articlePage = null;
	$(".article").live('tap',function () 
	{
		var id = this.getAttribute('id');
		//获得详情页面
		//预加载内容页
		plus.nativeUI.showWaiting('',{style:"white"});
		var page = mui.preload({
		    url:'content.html',
		    id:'content.html',//默认使用当前页面的url作为id
		    styles:{},//窗口参数 
		    extras:{}//自定义扩展参数
		});
		if (!articlePage) 
		{
			articlePage = plus.webview.getWebviewById('content.html');	
		} 
		//触发详情页面的newsid事件
		mui.fire(articlePage,'newsId',{
			id:id
		})
		//打开详情页
		plus.webview.show('content.html');
	})



})